/**********************
 * Noty Utils
 **********************/
var Noty = {
		defaultLayout : "topRight"
};
Noty.success = function(text, fn) {
	var ui = Noty.create(text, "success", Noty.defaultLayout, fn);
	Noty.autoClose(ui);
};
Noty.error = function(text, fn) {
	var ui = Noty.create(text, "error", Noty.defaultLayout, fn);
	Noty.autoClose(ui, 5000);
};
Noty.warning = function(text, fn) {
	var ui = Noty.create(text, "warning", Noty.defaultLayout, fn);
	Noty.autoClose(ui, 5000);
};
Noty.timeout = function(text, fn) {
	var ui = Noty.create(text, "warning", Noty.defaultLayout, fn);
	Noty.autoClose(ui);
};
Noty.autoClose = function(ui, time) {
	setTimeout(function() {
		$J.noty.close(ui.options.id);
	}, time ? time : 3000);
};
Noty.create = function(text, type, layout, fn) {
	var n = noty({
  		text: text,
  		type: type,
		dismissQueue: true,
  		layout: layout,
  		modal: false,
  		theme: 'drzui',
  		animation: {
  			open: {opacity: "toggle", height: 'toggle'},
  			close: {opacity: "toggle", height: 'toggle'},
  			speed: 500
  		},
  		callback: {
  			afterClose: function() {
  				if (fn)
  					fn();
  			}
  		}
  	});
	return n;
};
Noty.confirm = function(text, fn) {
	var ui = Noty.createConfirm(text, "alert", Noty.defaultLayout, fn);
};
Noty.createConfirm = function(text, type, layout, fn) {
	var n = noty({
  		text: text,
  		type: type,
		dismissQueue: true,
  		layout: layout,
  		modal: false,
  		theme: 'drzui',
  		animation: {
  			open: {opacity: "toggle", height: 'toggle'},
  			close: {opacity: "toggle", height: 'toggle'},
  			speed: 500
  		},
  		buttons: [
	        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
	            $noty.close();
	            if (fn)
	            	fn();
	          }
	        },
	        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
	            $noty.close();
	          }
	        }
	      ]
  	});
	return n;
};